home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1995 / MacHack 1995.toast / Presentations / Presentations ’92 / Mike Engber (LISP) / MCL-talk.lisp < prev    next >
Lisp/Scheme  |  1992-06-11  |  8KB  |  252 lines

  1. (oou-dependencies :records-u
  2.                   :macptr-u
  3.                   :draggable-svm
  4.                   :droppable-svm
  5.                   :QuickDraw-u)
  6.  
  7. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  8. ;;; start with something simple
  9.  
  10. (print "hello, world")
  11.  
  12.  
  13. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  14. ;;; source for simple dialog box
  15. ;;; something equivalent will be generated by the interface editor
  16.  
  17. (setf *d* (make-instance 'dialog
  18.             :view-subviews (list
  19.                             (make-instance 'sequence-dialog-item
  20.                               :view-nick-name :seq
  21.                               :view-size #@(150 100)
  22.                               :table-vscrollp t
  23.                               :table-hscrollp nil)
  24.                             (make-instance 'button-dialog-item
  25.                               :view-nick-name :butt
  26.                               :dialog-item-text "push me"
  27.                               :dialog-item-action 'foo))))
  28.  
  29. ;pushing the button yields an error - undefined function foo
  30. ;no big deal we just define foo and try again
  31.  
  32. (defun foo (di) (ed-beep))
  33.  
  34. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  35. ;;; Process Manager
  36.  
  37. ;adapted from IM VI p. 29-11
  38. (with-returned-pstrs ((process-name ""))
  39.  
  40.   (rlet ((psn   :ProcessSerialNumber
  41.                 :highLongOfPSN 0
  42.                 :lowLongOfPSN  #$kNoProcess)
  43.          (spec  :FSSpec)
  44.          (pinfo :ProcessInfoRec
  45.                 :processInfoLength (rlength :ProcessInfoRec)
  46.                 :processName       process-name
  47.                 :processAppSpec    spec))
  48.  
  49.     (let ((name-list nil))
  50.       (loop
  51.         (unless (zerop (#_GetNextProcess psn)) (return name-list))
  52.         (unless (zerop (#_GetProcessInformation psn pinfo))
  53.           (error "getting process info"))
  54.         (push (%get-string process-name) name-list)))))
  55.  
  56.  
  57. ;make it into a fn - just wrap code in:
  58.  
  59. (defun get-process-list ()
  60.  
  61.   ;;insert code here
  62.  
  63.   )
  64.  
  65.  
  66. (defun foo (di)
  67.   (set-table-sequence (find-named-sibling di :seq) (get-process-list)))
  68.  
  69. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  70. ;;; DeskTop DataBase
  71.  
  72. ;See DTDB.lisp
  73.  
  74.  
  75. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  76. ;;; multiple inheritance & mixin classes
  77.  
  78. (defclass drag-item (draggable-svm static-text-dialog-item) ())
  79.  
  80.  
  81. (setf *test-w*
  82.       (make-instance
  83.         'dialog
  84.         :window-type   :document
  85.         :view-position :centered
  86.         :view-size     #@(200 100)
  87.         :window-title  "draggable-svm demo"
  88.         :close-box-p   t
  89.         :grow-icon-p   t
  90.         :view-subviews
  91.         (list (make-instance
  92.                 'drag-item
  93.                 :view-position      #@(10 20)
  94.                 :dialog-item-text   "change my position"
  95.                 :view-nick-name     :i1
  96.                 :dialog-item-action #'(lambda (di)
  97.                                         (declare (ignore di))
  98.                                         (ed-beep))
  99.                 :drag-end-action-fn #'(lambda (sv delta pt)
  100.                                         ;end action moves the item
  101.                                         (declare (ignore pt))
  102.                                         (offset-view-position sv delta))
  103.                 :drag-bounds :window
  104.                 )
  105.               
  106.               (make-instance
  107.                 'drag-item
  108.                 :view-position      #@(10 50)
  109.                 :dialog-item-text   "drag me anywhere"
  110.                 :view-nick-name     :i2
  111.                 :dialog-item-action #'(lambda (di)
  112.                                         (declare (ignore di))
  113.                                         (print "hi,ho"))
  114.                 :drag-action-fn     #'(lambda (di)
  115.                                         (declare (ignore di))
  116.                                         (ed-beep))
  117.                 :drag-bounds        :none
  118.                 ))))
  119.  
  120. ;;nothing special about static text
  121. ;; redefine drag-item as a button & recreate the dialog
  122. (defclass drag-item (draggable-svm button-dialog-item) ())
  123.  
  124.  
  125. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  126. ;;; macros
  127.  
  128. ;;blast some text into the listener
  129. (with-focused-view *top-listener*
  130.   (with-text-state (:txSize 48 :txFace (ash 1 #$italic))
  131.     (#_MoveTo 20 60)
  132.     (with-pstrs ((str "the quick brow fox"))
  133.       (#_DrawString str))))
  134.  
  135. ;;fix up listener
  136. (invalidate-view *top-listener*)
  137.  
  138.  
  139. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  140. ;;; What's 1000!
  141.  
  142. (defun fact (n) (if (plusp n) (* n (fact (1- n))) 1))
  143.  
  144. (fact 1000)
  145.  
  146.  
  147. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  148. ;;; Compiles in LISP, C, Pascal, and Fortran
  149.  
  150.                                                                         (* pi);/*
  151.                                                                         #|
  152. */ main()  { puts ("Compiled by a C compiler"); }     /*
  153. * |# (print "Compiled by a Lisp compiler") #| *)
  154.       program chameleon                                                      (*
  155. *)                 (output);                                            (*
  156. *)    begin
  157.                                                                    writeln (*
  158.      1 ( *,* ) 'Compiled by a FORTRAN compiler'
  159. *)            ('Compiled by a Pascal compiler');
  160.       end                                                               .  (*/
  161. #define end_pascal_comment |#'( *)
  162.  
  163.  
  164. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  165. ;;; Compiles in LISP, C, and Pascal
  166.  
  167. (* pi);/*
  168. #|
  169. */ main()  { puts ("Compiled by a C compiler"); } /*
  170. |# (print "Compiled by a Lisp compiler") #| *)
  171. program chameleon (output);
  172.   begin
  173.     writeln('Compiled by a Pascal compiler');
  174.   end.
  175. (*/
  176. #define end_pascal_comment |#'( *)
  177.  
  178.  
  179.  
  180. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  181. ;;; RSA
  182.  
  183.  
  184. ;;1st load RSA.lisp
  185.  
  186. (defvar pub)
  187. (defvar pri)
  188.  
  189. (multiple-value-setq (pub pri) (RSA-gen-keys 47251 35747))
  190.  
  191. ;;encode & decode
  192. (RSA-decode-string (RSA-encode-string "the rain in spain" pub) pri)
  193.  
  194. ;;digital signature
  195. (RSA-decode-string (RSA-encode-string "it's me 6/20/92" pri) pub)
  196.  
  197.  
  198. ;;use droppable mixin to create an rsa dialog item
  199. (defclass rsa-widget (droppable-svm static-text-dialog-item)
  200.   ((public-key   :accessor public-key
  201.                  :initarg  :public-key)
  202.    (private-key  :accessor private-key
  203.                  :initarg  :private-key)))
  204.  
  205. (defun encoder-fn (di target-di offset where)
  206.   (declare (ignore offset where))
  207.   (set-dialog-item-text target-di (RSA-encode-string
  208.                                    (dialog-item-text target-di)
  209.                                    (private-key di))))
  210.  
  211. (defun decoder-fn (di target-di offset where)
  212.   (declare (ignore offset where))
  213.   (set-dialog-item-text target-di (RSA-decode-string
  214.                                    (dialog-item-text target-di)
  215.                                    (public-key di))))
  216.  
  217. (setf *test-w*
  218.       (make-instance
  219.         'dialog
  220.         :window-type   :document
  221.         :view-position :centered
  222.         :view-size     #@(220 200)
  223.         :window-title  "rsa demo"
  224.         :close-box-p   t
  225.        :view-subviews
  226.         (list (make-instance
  227.                 'rsa-widget
  228.                 :private-key pri
  229.                 :view-position    #@(10 20)
  230.                 :dialog-item-text "drag & drop to encode"
  231.                 :view-nick-name   :i1
  232.                 :drop-action-fn   'encoder-fn
  233.                 :drag-bounds      :none
  234.                 )
  235.               
  236.               (make-instance
  237.                 'rsa-widget
  238.                 :public-key pub
  239.                 :view-position     #@(10 50)
  240.                 :dialog-item-text "drag & drop to decode"
  241.                 :view-nick-name   :i2
  242.                 :drop-action-fn   'decoder-fn
  243.                 :drag-bounds       :none
  244.                 )
  245.  
  246.               (make-instance
  247.                 'editable-text-dialog-item
  248.                 :wrap-p             t
  249.                 :view-position      #@(10 80)
  250.                 :view-size          #@(200 100)
  251.                 :dialog-item-text   "I sure hope the NSA isn't watching this demo"
  252.                 ))))